package com.bojx.cms.dao;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class QuestionDao {
	public long queryCount(){
		return Db.queryLong("select count(*) from cms_question where display='Y'");
	}
	public long queryCount(String keyword){
	    return Db.queryLong("select count(*) from cms_question where display='Y' and title like '%"+keyword+"%'"); 
	}
	public List<Record> queryQuestions(int start,int end){
		return Db.find("select id,depart_name,title,depart_name,create_time from cms_question where display='Y' order by id desc limit ?,?",start,end);
	}
	
	public List<Record> queryQuestions(int start,int end,String keyword){
		return Db.find("select id,depart_name,title,depart_name,create_time from cms_question where display='Y' and title like '%"+keyword+"%' order by id desc limit ?,?",start,end);
	}
	
	public Record queryQuestionById(long id){
		return Db.findFirst("select * from cms_question where display='Y' and id=?",id);
	}
	
	public List<Record> queryAnswersByQuesId(long quesId){
		return Db.find("select * from cms_answer where question_id=? and display='Y'",quesId);
	}
	
	public void saveAnswer(Record answerRecord){
		Db.save("cms_answer", answerRecord);
	}
}
